<template>
  <Layout>
    <Form ref="form1" :model="form1" :label-width="120">

      <Row class="query-form" >
        <Col span="8">
            <FormItem label="二级集团：">
                <two-level-org v-model="form1.twoLevelOrgId" />
            </FormItem>
        </Col>
        <Col span="8">
            <FormItem label="单位名称：" prop="order">
              <company-select v-model="form1.companyName" style="width:100%" />
                <!-- <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgname='setQueryOrgName'
                              :orgTree="true"
                              :setCurrentName="{label:form1.companyName,value:form1.companyId}"></cascader-dom> -->
            </FormItem>
        </Col>
        <!--<Col span="8">-->
          <!--<FormItem label="伤亡人员姓名：">-->
            <!--<Input type="text" v-model="form1.victim"></Input>-->
          <!--</FormItem>-->
        <!--</Col>-->
        <Col span="8" v-if="!switchFlag">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
        </Col>
        <Col span="8" v-else>
          <FormItem label="事故名称：">
            <Input type="text" v-model="form1.sartName"></Input>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form" >
        <Col span="8">
          <FormItem label="事故类别：">
            <Select v-model="form1.accTypeId">
              <Option v-for="item in typeList" :value="item.codingCodeId" :key="item.codingCodeId">{{                item.codingName}}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" offset="8">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>

      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!"
    @on-sort-change="sortChange"
           highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
              style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
              show-total show-sizer show-elevator/>
      </Col>
    </Row>

    <Modal :mask-closable="false" :transfer=false v-model="model1" :width=850 :title="add?'政府调查报告新增':'政府调查报告修改'"
           @on-cancel="onCancel"  class-name='limit-height-dialog' :styles="{height:'600px'}">
      <div>
        <Form ref='InputData' :model="InputData" :rules="ruleCustom" label-position="top">
          <div>
            <Row>
              <Col span='11'>
                <FormItem label="事故名称：" prop="briefId">
                  <Input v-model="InputData.sartName" placeholder="请选择事故名称" :readonly="true">
                  <Button slot="append" @click="openForSelect" icon="ios-search"></Button>
                  </Input>
                </FormItem>
              </Col>
              <Col span='11' offset="1">
                <FormItem label="事故类别：" prop="accTypeId">
                  <Input v-model="InputData.accTypeName" placeholder="请选择事故名称" :readonly="true"/>
                  <Input v-show="false" v-model="InputData.accTypeId" placeholder="请选择事故名称" :readonly="true"/>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span='11' >
                <FormItem label="事故时间：" prop="sartDate">
                  <DatePicker v-model="InputData.sartDate" type="date" style="width: 100%;"
                              placeholder="请输入" :readonly="true"></DatePicker>
                </FormItem>
              </Col>
              <Col span='11' offset="1">
                <FormItem label="报告完成时间：" prop="completionTime">
                  <DatePicker v-model="InputData.completionTime" type="date" style="width: 100%;"
                              placeholder="请输入" ></DatePicker>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span='11'>
                <FormItem label="政府罚款金额(万元)：" prop="penaltyAmount">
                  <InputNumber style="width: 100%;" :min="0" v-model="InputData.penaltyAmount"></InputNumber>
                </FormItem>
              </Col>
              <Col span='11' offset="1">
                <FormItem label="保险公司赔付金(万元)：" prop="compensation">
                  <InputNumber style="width: 100%;"  :min="0" v-model="InputData.compensation"></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row v-if="InputData.sartName">
              <Col span="23" class="query-form">
                <p>事故伤亡人员信息</p>
                <Table highlight-row stripe border style="margin-top:10px;margin-bottom: 10px" :max-height="350" :columns="columnsItem"
                       :data="InputData.briefItems">
                </Table>
              </Col>
            </Row>
            <Row>
              <Col span="23">
                <FormItem label="事故调查报告：" prop="uploadList">
                  <div>
                    <Upload ref="upload"
                            :before-upload="beforeUpload"
                            :show-upload-list="true"
                            :max-size="10240"
                            multiple
                            type="drag"
                            :action="fileUrl">
                      <div style="padding: 10px">
                        <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                        <p>点击将文件拖拽到这里上传</p>
                        <span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>
                      </div>
                    </Upload>
                  </div>
                  <div v-show="uploadList.length>0" v-for="(item,index) in uploadList" :key='item'>
                    <a @click="downloadFile(InputData.id,item,index)">{{ item.fileName }}</a>
                    <Button type="text" icon="md-trash" @click="remove1(item.id,'1')"
                            style="margin-left: 5px;margin-bottom: 3px"/>
                    <Progress v-show="uploadListVisible[index]" :percent="uploadListPercent[index]"></Progress>
                  </div>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span="23">
                <FormItem label="政府罚款单：" >
                  <div>
                    <Upload ref="upload1"
                            :before-upload="beforeUploadGovernmentfine"
                            :show-upload-list="true"
                            :max-size="10240"
                            multiple
                            type="drag"
                            :action="fileUrl">
                      <div style="padding: 10px">
                        <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                        <p>点击将文件拖拽到这里上传</p>
                        <span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>
                      </div>
                    </Upload>
                  </div>
                  <div v-show="uploadList1.length>0" v-for="(item,index) in uploadList1" :key='item'>
                    <a @click="downloadFile1(InputData.id,item,index)">{{ item.fileName }}</a>
                    <Button type="text" icon="md-trash" @click="remove1(item.id,'2')"
                            style="margin-left: 5px;margin-bottom: 3px"/>
                    <Progress v-show="uploadListVisible1[index]" :percent="uploadListPercent1[index]"></Progress>
                  </div>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span="23">
                <FormItem label="工商保险赔付单：" >
                  <div>
                    <Upload ref="upload2"
                            :before-upload="beforeUploadInsurance"
                            :show-upload-list="true"
                            :max-size="10240"
                            multiple
                            type="drag"
                            :action="fileUrl">
                      <div style="padding: 10px">
                        <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                        <p>点击将文件拖拽到这里上传</p>
                        <span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>
                      </div>
                    </Upload>
                  </div>
                  <div v-show="uploadList2.length>0" v-for="(item,index) in uploadList2" :key='item'>
                    <a @click="downloadFile2(InputData.id,item,index)">{{ item.fileName }}</a>
                    <Button type="text" icon="md-trash" @click="remove1(item.id,'3')" style="margin-left: 5px;margin-bottom: 3px" />
                    <Progress  v-show="uploadListVisible2[index]" :percent="uploadListPercent2[index]"></Progress>
                  </div>
                </FormItem>
              </Col>
            </Row>

          </div>
          <!-- <Row type="flex" justify="center" class="code-row-bg">
               <Col span="23">
                   <FormItem>
                       <Button class='ivu-btn-save' :loading="buttonLoading" @click="submit('InputData')">确定</Button>
                       <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
                   </FormItem>
               </Col>
           </Row>-->
        </Form>
      </div>
      <div slot="footer">
        <Button class='ivu-btn-save' :loading="buttonLoading" @click="submit('InputData')">确定</Button>
        <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
      </div>
    </Modal>

    <Modal :transfer=false v-model="model3" :width=850 :styles="{height:'600px'}" title="政府调查报告详情" @on-cancel="onCancel">
      <Form :model="InputData" label-position="top">
        <div >
          <Row style="line-height: 42px;margin-left: 20px">
            <Col span='11'>
              <span>事故名称：{{InputData.sartName}}</span>
            </Col>
            <Col span='11' offset="1">
              <span>事故类别：{{InputData.accTypeName}}</span>
            </Col>

          </Row>
          <Row class="detail-background-clor" style="line-height: 42px;margin-left: 20px">
            <Col span='11'>
              <span>事故时间：{{ this.formatDate(new Date(InputData.sartDate),'yyyy-MM-dd')}}</span>
            </Col>
            <Col span='11' offset="1">
              <span>报告完成时间：{{this.formatDate(new Date(InputData.completionTime),'yyyy-MM-dd')}}</span>
            </Col>
          </Row>
          <Row style="line-height: 42px;margin-left: 20px">
            <Col span='11'>
              <span>政府罚款金额(万元)：{{ InputData.penaltyAmount }}</span>
            </Col>
            <Col span='11' offset="1">
              <span>保险公司赔付金(万元)：{{ InputData.compensation }}</span>
            </Col>
          </Row>
          <Row >
            <Col span="23" class="query-form" style="margin-left: 20px">
              <p>事故伤亡人员信息</p>
              <Table highlight-row stripe border style="margin-top:10px;margin-bottom: 10px" :max-height="350" :columns="columnsItem"
                     :data="InputData.briefItems">
              </Table>
            </Col>
          </Row>
          <Row class="detail-background-clor" style="line-height: 42px;margin-left: 20px">
            <Col span='11'>
              <span>创建人：{{ InputData.userName }}</span>
            </Col>
            <Col span='11'>
              <span>创建时间：{{ this.formatDate(new Date(InputData.createDate), 'yyyy-MM-dd') }}</span>
            </Col>
          </Row>

          <Row class="detail-background-clor" style="line-height: 42px;margin-left: 20px">
            <Col span="23">
              <FormItem label="事故调查报告：">
                <div v-show="uploadList.length>0" v-for="(item,index) in uploadList" :key='item'>
                  <a @click="downloadFile(InputData.id,item,index)">{{ item.fileName }}</a>
                  <Progress v-show="uploadListVisible[index]" :percent="uploadListPercent[index]"></Progress>
                </div>
              </FormItem>
            </Col>
          </Row>

          <Row  style="line-height: 42px;margin-left: 20px">
            <Col span="23">
              <FormItem label="政府罚款单：">
                <div v-show="uploadList1.length>0" v-for="(item,index) in uploadList1" :key='item'>
                  <a @click="downloadFile1(InputData.id,item,index)">{{ item.fileName }}</a>
                  <Progress v-show="uploadListVisible1[index]" :percent="uploadListPercent1[index]"></Progress>
                </div>
              </FormItem>
            </Col>
          </Row>
          <Row class="detail-background-clor" style="line-height: 42px;margin-left: 20px">
            <Col span="23">
              <FormItem label="工商保险赔付单：">
                <div v-show="uploadList2.length>0" v-for="(item,index) in uploadList2" :key='item'>
                  <a @click="downloadFile2(InputData.id,item,index)">{{ item.fileName }}</a>
                  <Progress v-show="uploadListVisible2[index]" :percent="uploadListPercent2[index]"></Progress>
                </div>
              </FormItem>
            </Col>
          </Row>

        </div>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="onCancel">关闭</Button>
      </div>
    </Modal>

    <Modal title="事故简报" :transfer=false footer-hide v-model="briefingList" :width=900>
      <FollowReportForSelect @getSelectData="getSelectData">
      </FollowReportForSelect>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '../../../../api/index.js'
import {sessionStorage} from '../../../../common/cacheUtils.js';
import FollowReportForSelect from '../followReport/followReportForSelect.vue';
import cascaderDom from "../../../../components/cascader-dom.vue"

export default {
  name: "interestedPartiesBlack",
  components: {FollowReportForSelect, cascaderDom},
  data() {
    return {
      briefingList: false,
      uploadList: [],
      uploadList1: [],
      uploadList2: [],
      tableHeight: '',
      loading: false,
      uploadListVisible: [],
      uploadListPercent: [],

      uploadListVisible1: [],
      uploadListPercent1: [],

      uploadListVisible2: [],
      uploadListPercent2: [],
      form1: {
        admittanceOrg: '',
        contractorName: '',
      },
      switchFlag: false,
      injuryLevels: [],
      memberships: [],
      sexList: [
        {
          value: '0',
          text: '男'
        },
        {
          value: '1',
          text: '女'
        }
      ],
      pageSizeArray: [10, 20, 50],
      pagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      dataTable: [],
      appesaseList: [],
      ruleCustom: {

        briefId: [{
          validator: (rule, value, callback) => {
            if (this.InputData.briefId == null || this.InputData.briefId == '' || this.InputData.briefId == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        position: [{
          validator: (rule, value, callback) => {
            if (this.InputData.position == null || this.InputData.position == '' || this.InputData.position == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        accTypeName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.accTypeName == null || this.InputData.accTypeName == '' || this.InputData.accTypeName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        injuryLevelName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.injuryLevelName == null || this.InputData.injuryLevelName == '' || this.InputData.injuryLevelName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        membershipName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.membershipName == null || this.InputData.membershipName == '' || this.InputData.membershipName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        penaltyAmount: [{
          validator: (rule, value, callback) => {
            if (!this.InputData.penaltyAmount == null || this.InputData.penaltyAmount == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        compensation: [{
          validator: (rule, value, callback) => {
            if (this.InputData.compensation == null || this.InputData.compensation == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        uploadList: [{
          validator: (rule, value, callback) => {
            if (this.uploadList == 0) {
              callback('请上传附件')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        completionTime: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
      },
      columns1: [
        {
          title: "序号",
          width: 80,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
          }
        },
          {title: '事故名称', align: 'center', key: 'sartName', minWidth: 120,},
          {title: '事故单位', align: 'center', key: 'reportOrgName', minWidth: 150, tooltip: true},
          {title: '事故类别', align: 'center', key: 'accTypeName', minWidth: 100,},
          {title: '事故时间', align: 'center', key: 'sartDate',minWidth: 100,sortable: "custom", 
              render: (h, params) => {return h('div', [(this.formatDate(new Date(params.row.sartDate), 'yyyy-MM-dd'))]);}},
          {title: '报告完成时间', align: 'center', key: 'completionTime',minWidth: 100,sortable: "custom", 
              render: (h, params) => {return h('div', [(this.formatDate(new Date(params.row.completionTime), 'yyyy-MM-dd'))]);}},
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: 200,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('A', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                },
                on: {
                  click: () => {
                    this.InputData = JSON.parse(JSON.stringify(params.row));
                    this.InputData.completionTime = this.formatDate(new Date(this.InputData.completionTime), 'yyyy-MM-dd');
                    this.InputData.createDate = this.formatDate(new Date(this.InputData.createDate), 'yyyy-MM-dd');
                    this.getFiles();
                    this.getGovernmentfine();
                    this.getInsurance();
                    this.model3 = true;
                  }
                }
              }, '详情'), h('Divider', {
                props: {
                  type: 'vertical',
                }
              }, ''),
              h('A', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                },
                on: {
                  click: () => {
                    this.InputData = JSON.parse(JSON.stringify(params.row));
                    this.InputData.completionTime = this.formatDate(new Date(this.InputData.completionTime), 'yyyy-MM-dd');
                    this.InputData.createDate = this.formatDate(new Date(this.InputData.createDate), 'yyyy-MM-dd');
                    this.getFiles();
                    this.getGovernmentfine();
                    this.getInsurance();
                    this.model1 = true;
                    this.add = false
                  }
                }
              }, '修改'), h('Divider', {
                props: {
                  type: 'vertical',
                }
              }, ''),
              h('A', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                  color: 'red',
                },
                on: {
                  click: () => {
                    this.$Modal.confirm({
                      title: '提示',
                      content: '<p>是否要删除？</p>',
                      onOk: () => {
                        this.deleteData(params.row);
                      },
                      onCancel: () => {
                      }
                    });
                  }
                }
              }, '删除')
            ]);
          }
        }
      ],
      add: false,
      InputData: {deptLeaderId: '', deptLeaderName: ''},

      buttonLoading: false,
      model2: false,
      model1: false,
      model3: false,
      membershipList: [],
      typeList: [],
      injuryLeveList: [],
      fileUrl: Api.interestedPartiesUserFile,
        columnsItem: [
            // {title: '序号', width: 70, align: 'center', render: this.indexColumnsRender},
            {title: '伤亡人员姓名', align: 'center', key: 'victim', minWidth: 100,},
            {title: '性别', align: 'center', key: 'gender', minWidth: 80,render: (h, params) => {
                    return h('span', params.row.gender == '0' ? '男' : '女')}},
            {title: '年龄', align: 'center', key: 'age', minWidth: 80,},
            {title: '工种或岗位', align: 'center', key: 'position', minWidth: 120,},
            {title: '伤害部位', align: 'center', key: 'injured', minWidth: 120,},
            {title: '就业类型', align: 'center', key: 'membershipName', minWidth: 120,},
            {title: '伤害程度', align: 'center', key: 'injuryLevelName', minWidth: 120,},
            {title: '歇工天数', align: 'center', key: 'daysWork', minWidth: 100,},
            {title: '直接经济损失(万元)', align: 'center', key: 'loseMoney', minWidth: 120,},
        ],
    }
  },
  mounted() {
    this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
    this.query()
    this.selectCodingSort();
  },
  methods: {
    sortChange(data) {
		    if (data.order === 'asc'||data.order ==='desc') {
		        let order = data.key
		        this.form1.dynamicSort = order +' '+ data.order
		        this.query()
		    }
		},
    openForSelect() {
      this.briefingList = true;
    },
    getSelectData(row) {
        this.InputData.accTypeName = row.accTypeName
        this.InputData.accTypeId = row.accTypeId
        this.InputData.sartName = row.sartName;
        this.InputData.briefId = row.briefId;
        this.InputData.sartDate = row.sartDate;
        this.InputData.victim = row.victim;
        this.InputData.damage = row.loseMoney;
        this.InputData.briefItems = row.briefItems;
      this.briefingList = false;
    },

    downloadFile(guideId, file, index) {
      let url = this.fileUrl + '/file/' + file.id;
      this.uploadListVisible[index] = true;
      var _this = this;
      this.$http.get(url, {
        responseType: 'blob',      //告诉服务器我们需要的响应格式
        progress: function (e) {
          _this.$set(_this.uploadListPercent, index, 100 * (e.loaded / e.total));
        }
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = file.fileName //标题
        aLink.click()
        document.body.appendChild(aLink)
      })
    },
    downloadFile1(guideId, file, index) {
      let url = this.fileUrl + '/file/' + file.id;
      this.uploadListVisible1[index] = true;
      var _this = this;
      this.$http.get(url, {
        responseType: 'blob',      //告诉服务器我们需要的响应格式
        progress: function (e) {
          _this.$set(_this.uploadListPercent1, index, 100 * (e.loaded / e.total));
        }
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = file.fileName //标题
        aLink.click()
        document.body.appendChild(aLink)
      })
    },
    downloadFile2(guideId, file, index) {
      let url = this.fileUrl + '/file/' + file.id;
      this.uploadListVisible2[index] = true;
      var _this = this;
      this.$http.get(url, {
        responseType: 'blob',      //告诉服务器我们需要的响应格式
        progress: function (e) {
          _this.$set(_this.uploadListPercent2, index, 100 * (e.loaded / e.total));
        }
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = file.fileName //标题
        aLink.click()
        document.body.appendChild(aLink)
      })
    },
    remove1(id,type) {
      let url = this.fileUrl + '/file/' + id;
      this.$http.delete(url).then((res) => {
        if (type == '1'){
          this.getFiles()
        }else if (type == '2'){
          this.getGovernmentfine()
        }else if(type == '3'){
          this.getInsurance()
        }

      })
    },
    beforeUpload(file) {
      let formData = new FormData();
      formData.append("files", file); // 文件对象
      let url = this.fileUrl + '/' + this.InputData.id + '/files/government'
      this.$http.post(url, formData).then((res) => {
        if (res.data.result == "success") {
          this.$Message.info("文件上传成功")
          this.getFiles();
        }
      })
      return false
    },
    beforeUploadGovernmentfine(file) {
      let formData = new FormData();
      formData.append("files", file); // 文件对象
      let url = this.fileUrl + '/' + this.InputData.id + '/files/governmentfine'
      this.$http.post(url, formData).then((res) => {
        if (res.data.result == "success") {
          this.$Message.info("文件上传成功")
          this.getGovernmentfine();
        }
      })
      return false
    },
    beforeUploadInsurance(file) {
      let formData = new FormData();
      formData.append("files", file); // 文件对象
      let url = this.fileUrl + '/' + this.InputData.id + '/files/insurance'
      this.$http.post(url, formData).then((res) => {
        if (res.data.result == "success") {
          this.$Message.info("文件上传成功")
          this.getInsurance();
        }
      })
      return false
    },
    getFiles() {
      let url = this.fileUrl + '/' + this.InputData.id + '/files/government'
      this.$http.get(url).then((res) => {
        if (res.data.result == "success") {
          this.uploadList = res.data.data
          let index = 0;
          this.uploadList.forEach(item => {
            this.uploadListPercent[index] = 0;
            this.uploadListVisible[index] = false;
            index++;
          })
        }
      })
    },
    getGovernmentfine() {
      let url = this.fileUrl + '/' + this.InputData.id + '/files/governmentfine'
      this.$http.get(url).then((res) => {
        if (res.data.result == "success") {
          this.uploadList1 = res.data.data
          let index = 0;
          this.uploadList1.forEach(item => {
            this.uploadListPercent1[index] = 0;
            this.uploadListVisible1[index] = false;
            index++;
          })
        }
      })
    },
    getInsurance() {
      let url = this.fileUrl + '/' + this.InputData.id + '/files/insurance'
      this.$http.get(url).then((res) => {
        if (res.data.result == "success") {
          this.uploadList2 = res.data.data
          let index = 0;
          this.uploadList2.forEach(item => {
            this.uploadListPercent2[index] = 0;
            this.uploadListVisible2[index] = false;
            index++;
          })
        }
      })
    },
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 44;
      } else {
        this.tableHeight = this.tableHeight - 44;
      }
    },

    onCancel() {
      this.InputData = {}
      this.model1 = false
      this.model3 = false
      this.query();

    },
    submit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.buttonLoading = true
          if (this.InputData.completionTime == null || this.InputData.completionTime == undefined || this.InputData.completionTime == '') {
            this.InputData.completionTime = null;
          } else {
            this.InputData.completionTime = this.formatDate(new Date(this.InputData.completionTime), 'yyyy-MM-dd');
          }
          if (this.add) {
            let url = Api.saveAnnual
            this.InputData.bsflag = '0'
            this.InputData.createOrgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
            this.InputData.createUserId = sessionStorage('userId').getObject('userId').userId
            this.$http.post(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.query()
              this.buttonLoading = false
              this.model1 = false
            }).catch(e => {
              this.$Message.error('请求失败');
            })
          } else {
            let url = Api.updateAnnual;
            this.InputData.updateUserId = sessionStorage('userId').getObject('userId').userId
            this.InputData.updateOrgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
            this.$http.put(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.buttonLoading = false
              this.model1 = false
              this.query()
            }).catch(e => {
              this.$Message.error('请求失败');
            })
          }
        } else {
          this.$Message.error('请填报完整!');
        }
      })

    },
    selectCodingSort() {
      this.$http.get(Api.queryCodeDetailBySortId + '/MEM-000001', {params: {}}).then((res) => {
        this.membershipList = res.data.data;
      });
      this.$http.get(Api.queryCodeDetailBySortId + '/ACC-000001', {params: {}}).then((res) => {
        this.typeList = res.data.data;
      });
      this.$http.get(Api.queryCodeDetailBySortId + '/1000001019', {params: {}}).then((res) => {
        this.injuryLeveList = res.data.data;
      });
    },

    deleteData(row) {
      let url = Api.follow

      this.$http.deleteAnnual(url + "/" + row.id).then((res) => {
        this.$Message.success('成功');
        this.query()
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    addInfo() {
      this.uploadList = [];
      this.uploadList1 = [];
      this.uploadList2 = [];
      this.add = true;
      this.InputData = {
        id: this.get_uuid(),
        rptType: '1',
        penaltyAmount: 0,
        compensation: 0,
      };
      this.model1 = true;
    },
    query() {
      let data = {
        startPage: this.pagedata.currentPage,
        size: this.pagedata.pageSize,
        orgId: sessionStorage('userId').getObject('userId').companyId,
        rptType: '1',
      };
      data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
      let url = Api.queryAnnual
      this.loading = true;
      this.$http.get(url, {params: data}).then((res) => {
        this.dataTable = res.data.data.data;
        this.pagedata.total = res.data.data.totalSize;
        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    reset() {
      this.form1 = {};
      this.pagedata.currentPage = 1;
      this.query();
    },
    pageChange(pageNum) {
      this.pagedata.currentPage = pageNum;
      this.query();
    },
    pageSizeChange(pageSize) {
      this.pagedata.pageSize = pageSize;
      this.query();
    },
    get_uuid() {
      let s = [];
      let hexDigits = "0123456789abcdef";
      for (let i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
      s[14] = "4";
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
      s[8] = s[13] = s[18] = s[23] = "-";

      let uuid = s.join("");
      let reg = new RegExp("-", "g");
      let a = uuid.replace(reg, "");
      console.log(a);
      return a;
    },
    formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
      };
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + '';
          fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
        }
      }
      return fmt;
    },
    padLeftZero(str) {
      return ('00' + str).substr(str.length);
    },
  },
  watch: {},
}
</script>

<style scoped>
@import '../../../../index.css';

</style>
